home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cc04.arc / YARCSUP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-03-15  |  12.5 KB  |  705 lines

  1. /*
  2.     YARCSUP.C
  3.     NetWare Alloy Archive Utility Support Procedures
  4.     V4.42    02/04/84    by Mark Hurst
  5.  
  6.     For use with NetWare V4.n systems
  7.  
  8.     Copyright (C) 1983, 1984 by Novell, Inc.
  9. */
  10.  
  11.  
  12. #define LOCALBIT    0x80
  13. #define    PERMNET        0x01
  14. #define    TEMPNET        0x02
  15. #define    NETBITS        0x03
  16.  
  17. #define    READBIT        0x01
  18. #define    WRITEBIT    0x02
  19. #define    OPENBIT        0x04
  20. #define    CREATEBIT    0x08
  21. #define    DELETEBIT    0x10
  22. #define    OWNEDBIT    0x20
  23. #define    SEARCHBIT    0x40
  24. #define    MODIFYBIT    0x80
  25.  
  26. #include    "ctype.h"
  27. #include    "stdio.h"
  28.  
  29. #define        VARPATH        '^' - 'A'
  30.  
  31. #define        TRUE        1
  32. #define        FALSE        0
  33.  
  34. #define        MAXVOLUMES    16
  35. #define        MAXSPECS    100
  36. #define         LISTSIZE    250
  37.  
  38. #define        ALLMODE        1
  39. #define        MODMODE        2
  40. #define        SELMODE        3
  41.  
  42.  
  43. extern    FILE    *log;
  44. extern    int    source, target; /* low level I/O file numbers */
  45. extern    char    actarget[20];
  46.  
  47. extern    int    setvpath = FALSE; /* when TRUE => volume path set, continue archive */
  48.  
  49. extern    int    printlog, spool, nprinter, logcopies;
  50. extern    int    startup;
  51.  
  52. extern    int    system, continuous, finclude, fexclude;
  53. extern    char    *speclist[MAXSPECS];
  54. extern    int    speccount;
  55.  
  56. extern    int    numberqualified, numberout;
  57. extern    char    *calloc(), *malloc();
  58.  
  59. extern    unsigned known, firsttypecheck, unusabledisk;
  60.  
  61. typedef struct dosfcb {
  62.     char    drive;
  63.     char    fname[8];
  64.     char    fext[3];
  65.     unsigned curblk;
  66.     unsigned recsize;
  67.     long    size;
  68.     unsigned date;
  69.     char    reserved[10];
  70.     char    relrec;
  71.     char    record[4];
  72. } FCB;
  73.  
  74. typedef    struct exdirfcb {
  75.     char    dummy;
  76.     char    exset;
  77.     char    res[5];
  78.     char    flags;
  79.     char    drive;
  80.     char    fname[8];
  81.     char    fext[3];
  82.     char    gap[17];
  83.     char    size[4];
  84. } ExDirFCB;
  85.  
  86. typedef struct exdosfcb {
  87.     char    dummy;
  88.     char    exset;
  89.     char    res[5];
  90.     char    flags;
  91.     char    drive;
  92.     char    fname[8];
  93.     char    fext[3];
  94.     unsigned curblk;
  95.     unsigned recsize;
  96.     long    size;
  97.     unsigned date;
  98.     char    reserved[10];
  99.     char    relrec;
  100.     char    record[4];
  101. } ExFCB;
  102.  
  103. extern    unsigned unitsize, freeunits, freeslots;
  104.  
  105.  
  106. extern    int    mode, bdrive, firstcopy;
  107.  
  108. extern    char    pathstring[];
  109. extern    char    privmask;
  110.  
  111. extern    int    listcount;
  112. typedef    struct    liststruct {
  113.     struct liststruct *link;
  114.     char    name[12]; /* 1 too big for even allocation */
  115.     char    marked;
  116.     char    flags;
  117.     long    size;    /* size of file in bytes */
  118.     unsigned units;    /* size of file in allocation units */
  119. } LISTNODE;
  120.  
  121. extern    LISTNODE *list[], *curnode;
  122.  
  123. extern    ExFCB    sourcefile;
  124. extern    ExFCB    destfile;
  125.  
  126.  
  127. extern    int    logexists; /* flag; TRUE means there is an existing log file */
  128. extern    FCB    logfcb;
  129.  
  130. int    imin(a, b)
  131. int    a,b;
  132. {
  133.     if (a<b) return (a);
  134.     else return (b);
  135. }
  136.  
  137. unsigned umin(a, b)
  138. unsigned a,b;
  139. {
  140.     if (a<b) return (a);
  141.     else return (b);
  142. }
  143.  
  144. long     lmin(a, b)
  145. long    a,b;
  146. {
  147.     if (a<b) return (a);
  148.     else return (b);
  149. }
  150.  
  151. char    inline[80];
  152. /* buffered input of strings from console.  Forces first character to
  153.    be non-space.  returns first byte of input string.  If break character
  154.    detected, then the entire string is converted to 0x03, 0x00
  155. */
  156. char    getstr(t, mx)
  157. int    mx;
  158. char    *t;
  159. {
  160.     int    i, j;
  161.     char    ch;
  162.  
  163.     i = 0;
  164.     while ((ch=getch()) != 0x0D && ch != 0x03 && ch != 0x1B) {
  165.         switch(ch) {
  166.         case 0x08: /* backspace */
  167.             if (i) {
  168.                 i--;
  169.                 cprintf("\10 \10");
  170.             }
  171.             break;
  172.         default:
  173.             if (ch < 0x20) break;
  174.             if (!i && ch == 0x20) break;
  175.             if (i >= mx) {putch(7); break;}
  176.             putch(ch);
  177.             t[i++] = ch;
  178.         }
  179.     }
  180.     if (ch == 0x0D) {
  181.         t[i] = 0;
  182.         return (t[0]);
  183.     }
  184.     /* BREAK CHARACTER or ESCAPE DETECTED, CANCEL LINE and return char */
  185.     
  186.     t[0] = ch;
  187.     t[1] = 0;
  188.     return (ch);
  189. }
  190.  
  191. yes(q)
  192. char    *q;
  193. {
  194.     char    ch;
  195.  
  196.     ch = 'x';
  197.     while (ch != 'Y' && ch != 'N') {
  198.         cprintf("%s", q);
  199.         ch = getstr(inline, 3);
  200.         if (ch == 3) abort();
  201.         ch = toupper(ch);
  202.         if (!ch) {ch = 'N'; cprintf("No");}
  203.         cprintf("\r\n");
  204.     }
  205.     if (ch == 'Y') return (TRUE);
  206.     else return (FALSE);
  207. }
  208.  
  209. invertword(pword)
  210. char *pword;
  211. {
  212.     char    temp;
  213.  
  214.     temp = pword[0];
  215.     pword[0] = pword[1];
  216.     pword[1] = temp;
  217. }
  218.  
  219.  
  220.  
  221. struct    PathOutStruct {
  222.     int        totallength;
  223.     char        fcode;
  224.     char        drive;
  225.     char        pathlen;
  226.     char        pathname[256];
  227. } path_out;
  228.  
  229. struct    PathInStruct {
  230.     int        totallength;
  231.     char        pathlen;
  232.     char        pathname[256];
  233. } path_in;
  234.  
  235.  
  236.  
  237.  
  238.  
  239. /*    SECTION TO SET THE DIRECTORY PATH MAPPINGS AND MODIFY THEM
  240.         AS THE SUBDIRECTORY STRUCTURE IS TRAVERSED
  241. */
  242.  
  243.  
  244. NewTemp (drive, handle, path)
  245.     int    drive, handle;
  246.     char    *path;
  247. {
  248.     int    old, new, ccode, length;
  249.     char    flag, s[300], r[40];
  250.  
  251.     old = GetHandle (drive, &flag);
  252.     s[1] = 0;
  253.     s[2] = 19;
  254.     s[3] = handle;
  255.     s[4] = drive + 'A';
  256.     s[5] = strlen(path);
  257.     strcpy(&s[6], path);
  258.     length = 4 + s[5];
  259.     movmem(&length, s, 2);
  260.  
  261.     r[0] = 38;
  262.     r[1] = 0;
  263.     ccode = DirPath (s, r);
  264.     if (ccode == 0xFE) LockError();
  265.     else if (ccode) return (ccode);
  266.     new = r[2];
  267.     if (old != 0) {
  268.         /*release old handle*/
  269.         s[0] = 2;
  270.         s[1] = 0;
  271.         s[2] = 20;
  272.         s[3] = old;
  273.         DirPath (s, r);
  274.     }
  275.     return (0);
  276. }
  277.  
  278.  
  279.  
  280. firstpath (line)
  281.     char    *line;
  282.     /* SET PATH TO SPECIFICATION GIVEN BY USER */
  283. {
  284.     int        i, ccode;
  285.     char        ans[128], type, ctype;
  286.     int        fdrive, sdrive;
  287.  
  288.     compress(line);
  289.     GetHandle (curdisk(), &ctype);
  290.  
  291.     if (*line == '\0') {
  292.         if (ctype == LOCALBIT) {
  293.             error("Local drives have no Subdirectories.");
  294.             myexit(0);
  295.         }
  296.         fdrive = CurDisk();
  297.     }
  298.     else { 
  299.         if (line[1]==':' && (line[2]=='/' || line[2]==':' ||
  300.                !line[2] || line[2]=='~' || line[2]=='.')) {
  301.             fdrive = line[0] - 'A';
  302.             GetHandle(fdrive, &type);
  303.             if (type == LOCALBIT) {
  304.                 error("Local Drives have no Subdirectories.");
  305.                 myexit(0);
  306.             }
  307.             if (!type) {
  308.                 error("Specified drive does not exist.");
  309.                 myexit(0);
  310.             }
  311.             line = &line[2];
  312.         }
  313.         else if (ctype == LOCALBIT) {
  314.             /* assume full pathname was specified */
  315.             if (setpath(VARPATH, line)) {
  316.                 error("Local Drives have no Subdirectories.");
  317.                 myexit(0);
  318.             }
  319.             return;
  320.         }
  321.         else fdrive = CurDisk();
  322.     }
  323.     pathmodset (VARPATH, fdrive, line);
  324. }
  325.  
  326. pathmodset(d, fd, mp)
  327.     /* SET DRIVE D TO PATH OF DRIVE FD AS MODIFIED BY STRING MP */
  328.     int    d, fd;
  329.     char    *mp; /* pointer to path name string */
  330. {
  331.     char    ccode, handle, type;
  332.  
  333.     handle = GetHandle(fd, &type);
  334.     ccode = NewTemp(d, handle, mp);
  335.     if (ccode) {
  336.         error("Error setting path mapping.");
  337.         myexit(0);
  338.     }
  339. }
  340.  
  341.  
  342. setpath (d, p)
  343.     int    d;    char    *p;
  344.     /* SET DRIVE D TO PATH P */
  345. {
  346.     return (NewTemp(d, 0, p));
  347. }
  348.  
  349.  
  350.  
  351. getcurpath(d, s)
  352.     int    d;
  353.     char    *s;
  354.     /* GET PATH OF DRIVE D INTO STRING S */
  355. {
  356.     char    ccode, type;
  357.  
  358.     ccode = getpath(GetHandle(d, &type), s);
  359.     if (ccode) {
  360.         error ("Error getting path mapping from.");
  361.         myexit(0);
  362.     }
  363. }
  364.  
  365.  
  366. getpath (handle, buffer)
  367.     char    handle;
  368.     char    *buffer;
  369. {
  370.     char    s[10], r[300], ccode;
  371.     unsigned length;
  372.  
  373.     s[0] = 2;
  374.     s[1] = 0;
  375.     s[2] = 1;
  376.     s[3] = handle;
  377.     length = 295;
  378.     movmem(&length, r, 2);
  379.     ccode = DirPath(s, r);
  380.     if (ccode == 0xFE) LockError();
  381.     if (ccode) return (ccode);
  382.     r[r[2] + 3] = 0;
  383.     strcpy(buffer, &r[3]);
  384.     return (0);
  385. }
  386.  
  387.  
  388.  
  389. /*    --------- STRING PRIMITIVES -----------    */
  390.  
  391.  
  392. compress(s)
  393. char    *s;
  394. {
  395.     char    *c = s, ch;
  396.  
  397.     while (*s) if (!isspace(ch=*s++)) *c++ = ch;
  398.     *c = '\0';
  399. }
  400.  
  401.  
  402. SetB (byte, buff, len)
  403.     char        byte, *buff;
  404.     int        len;
  405. {
  406.     while (len-- > 0) *buff++ = byte;
  407. }
  408.  
  409. CmpB (b1, b2, len)
  410.     register char    *b1, *b2; int    len;
  411. {
  412.     register int    i;
  413.  
  414.     for (i=0; i<len; i++)
  415.         if (*b1++ != *b2++) return (i);
  416.     return (-1);
  417. }
  418.  
  419. FindB (b, s, len)
  420.     char    b, *s;
  421.     int    len;
  422. {
  423.     int    i;
  424.  
  425.     for (i=0; i<len; i++) {
  426.         if (b == s[i]) return (i);
  427.     }
  428.     return (-1);
  429. }
  430.  
  431.  
  432.  
  433. conupper(t)
  434. char    *t;
  435. {
  436.     while (*t) {*t = toupper(*t); t++;}
  437. }
  438.  
  439.  
  440. LockError()
  441. {
  442.     error("The Supervisor has the Directory System locked.");
  443.     myexit(0);
  444. }
  445.  
  446.  
  447.  
  448.  
  449. /*    ROUTINES TO GET SUBDIRECTORIES OF A SPECIFIC PATH    */
  450.  
  451.  
  452. struct    scandirstruct {
  453.     int    totallen;
  454.     char    fcode;
  455.     char    handle;
  456.     char    subdir[2];
  457.     char    speclength;
  458.     char    path;
  459. } scan;
  460.  
  461. struct    dirret {
  462.     int    maxlen;
  463.     char    subname[16];
  464.     char    createtime[4];
  465.     char    user_unique[4];
  466.     char    mask;
  467.     char    pad_junk;
  468.     int    subnum;
  469. } subinfo;
  470.  
  471. intswap(i)
  472.     char    *i;
  473. {
  474.     char    temp;
  475.  
  476.     temp = i[0];
  477.     i[0] = i[1];
  478.     i[1] = temp;
  479. }
  480.  
  481.  
  482. getsubinfo(drive, subnum)
  483.     int    drive, subnum;
  484.     /* get subdirectory d's info */
  485. {
  486.     char    ccode, type, swap[2];
  487.     int    swapsubnum;
  488.  
  489.     scan.totallen = 6;
  490.     scan.fcode = 2;
  491.     scan.handle = GetHandle(drive, &type);
  492.     scan.subdir[0] = subnum >> 8;
  493.     scan.subdir[1] = subnum & 0xFF;
  494.     scan.speclength = 1;
  495.     scan.path = '*';
  496.     subinfo.maxlen = sizeof(struct dirret) - 2;
  497.     ccode = DirPath (&scan, &subinfo);
  498.     if (ccode == 0xFE) LockError();
  499.     intswap(&subinfo.subnum);
  500.     return (ccode);
  501. }
  502.  
  503.  
  504. checkrights(drive, pmask)
  505. char    drive, pmask;
  506. {
  507.     char    ccode, mask, type;
  508.     char    s[20], r[10];
  509.  
  510.     s[0] = 3;
  511.     s[1] = 0;
  512.     s[2] = 3;
  513.     s[3] = GetHandle(drive, &type);
  514.     s[4] = 0; /* NULL PATH MOD SPEC, ASSUME CURRENT PATH (.) */
  515.     r[0] = 8;
  516.     r[1] = 0;
  517.     ccode = DirPath (s, r);
  518.     if (ccode == 0xFE) LockError();
  519.     else if (ccode) return(FALSE); 
  520.     mask = r[2];
  521.     if (mask == 0xFF)  return (TRUE); /* OK TO BACK IT UP */
  522.     if ((mask & pmask) == pmask) return (TRUE);
  523.     else return (FALSE);
  524. }
  525.  
  526. showfile(f)
  527. FCB    *f;
  528. {
  529.     int    i, c;
  530.     char    ch;
  531.  
  532.     c = 0;
  533.  
  534.     for (i=0;i<8;i++) if ((ch=f->fname[i]) != 0x20) {putch(ch); c++;}
  535.  
  536.     if (f->fext[0] != 0x20) {
  537.         putch('.'); c++;
  538.         for (i=0;i<3;i++) if ((ch=f->fext[i]) != 0x20) {putch(ch);c++;}
  539.     }
  540.  
  541.     c = 15 - c;
  542.     for (i=0;i<c;i++) putch(' ');
  543. }
  544.  
  545.  
  546. addspecs(specs)
  547. char    *specs;
  548. {
  549.     int    ix, stix;
  550.  
  551.     compress(specs); conupper(specs);
  552.     ix = 0;
  553.     while (specs[ix]) {
  554.         stix = ix;    /* save start of scan */
  555.         while (specs[ix] && specs[ix] != ',') ix++;
  556.         if (specs[ix]) {
  557.             specs[ix] = 0; /* null out the comma */
  558.             addspec(&specs[stix]);
  559.             ix++;
  560.         }
  561.         else if (ix != stix) addspec(&specs[stix]);
  562.     }
  563. }
  564.  
  565. addspec(spec)
  566. char    *spec;
  567. {
  568.     char    *s = malloc(12), ch;
  569.     int    si, di, ix;
  570.  
  571.     si = di = 0;
  572.     setmem(s, 11, 0x20);
  573.     s[11] = 0;
  574.  
  575.     /* DO KLUGE TO MATCH DOS WILD MATCH-- "*" matches everything,
  576.        but "*." matches all without any extensions. */
  577.     if (!strcmp("*", spec)) setmem(&s[8], 3, '?');
  578.  
  579.     while (di < 8) {
  580.         ch = spec[si];
  581.         if (ch == '.') {
  582.             di = 8; /* end of file name, go on to get extension */
  583.         }
  584.         else if (!ch) {
  585.             di = 11; /* end of file spec */
  586.         }
  587.         else if (ch != '*') {
  588.             s[di++] = ch; 
  589.             si++;
  590.         }
  591.         else {
  592.             for (ix = di; ix < 8; ix++) s[ix] = '?';
  593.             di = 8;
  594.             while ((ch=spec[si]) && ch != '.') si++;
  595.         }
  596.     }
  597.  
  598.     if (speccount >= MAXSPECS) {
  599.         cprintf("File spec list full, entry \"%s\" ignored.\r\n\7",spec);
  600.         free(s);
  601.         return;
  602.     }
  603.     if (spec[si] && spec[si] != '.') {
  604.         /* IF MORE THAN 8 CHARS IN A ROW, IGNORE SPEC AS ILLEGAL */
  605.         cprintf("File spec \"%s\" illegal; entry ignored.\r\n\7",spec);
  606.         free(s);
  607.         return;
  608.     }
  609.  
  610.     speclist[speccount++] = s; /* ADD SPEC TO DYNAMIC LIST */
  611.     if (!spec[si]) return; /* no extension, return ok */
  612.  
  613.     si++; /* skip '.' */
  614.  
  615.     while (di < 11) {
  616.         ch = spec[si];
  617.         if (!ch) {
  618.             di = 11; /* end of file spec */
  619.         }
  620.         else if (spec[si] != '*') {
  621.             s[di++] = spec[si++];
  622.         }
  623.         else {
  624.             for (ix = di; ix < 11; ix ++) s[ix] = '?';
  625.             di = 11;
  626.             si++;
  627.         }
  628.     }
  629. }
  630.  
  631.  
  632. inexquery()
  633. {
  634.     char    specs[80];
  635.  
  636.     finclude, fexclude = FALSE;
  637.     speccount = 0;
  638.  
  639.     if (!yes(
  640. "Do you want to select or ignore files based on certain file specs? (Y/N) ")) 
  641.         return;
  642.  
  643.     cprintf("Enter list of file specs to be used for selecting files\r\n");
  644.     cprintf("or <RETURN> if none.  Multiple lines may be entered.\r\n");
  645.  
  646.     while (speccount < MAXSPECS) {
  647.         cprintf("> ");
  648.         if (getstr(specs, 77) == 3) abort();
  649.         cprintf("\r\n");
  650.         if (specs[0] == '\0') break;
  651.         finclude = TRUE;
  652.         addspecs(specs);
  653.     }
  654.  
  655.     if (finclude) return;
  656.  
  657.     /* ENTER EXCLUSION LIST INSTEAD */
  658.     cprintf("Enter list of file specs to be used for ignoring files\r\n");
  659.     cprintf("or <RETURN> if none.  Multiple lines may be entered.\r\n");
  660.     while (1) {
  661.         cprintf("> ");
  662.         if (getstr(specs, 77) == 3) abort();
  663.         cprintf("\r\n");
  664.         if (specs[0] == '\0') break;
  665.         fexclude = TRUE;
  666.         addspecs(specs);
  667.     }
  668. }
  669.  
  670. include(filename)
  671. char    *filename;
  672. {
  673.     if (!finclude) return (TRUE); /* accept any file if no specifics given*/
  674.  
  675.     /* RETURN TRUE IF THIS FILE MATCHES ANY OF THE INCLUSION LIST SPECS */
  676.     return (fmatch(filename));
  677. }
  678.  
  679. exclude(filename)
  680. char    *filename;
  681. {
  682.     if (!fexclude) return (FALSE); /* don't reject any file */
  683.  
  684.     /* RETURN TRUE IF THIS FILE MATCHES ANY OF THE EXCLUSION LIST SPECS */
  685.     return (fmatch(filename));
  686. }
  687.  
  688. fmatch(filename)
  689. char    *filename;
  690. {
  691.     char    *spec;
  692.     int    f, ix;
  693.  
  694.     for (f=0; f < speccount; f++) {
  695.         spec = speclist[f];
  696.         for (ix=0; ix < 11; ix++) {
  697.             if (spec[ix] != '?' && spec[ix] != filename[ix])
  698.                 goto nextspec;
  699.         }
  700.         return (TRUE);
  701.     nextspec: ;
  702.     }
  703.     return (FALSE);
  704. }
  705.